import time

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By


user_agent = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36")

dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = user_agent

driver = webdriver.PhantomJS(desired_capabilities=dcap, executable_path="/Users/xuwei/tools/phantomjs-2.1.1-macosx/bin/phantomjs")

driver.get("https://weibo.com/")

# time.sleep(8)

# 等待指定的标签
element = WebDriverWait(driver, 5, 0.5).until(
    EC.presence_of_element_located((By.ID, "loginname"))
)

element.send_keys("lixuweiok@sina.com")


# driver.find_element_by_id("loginname").send_keys("lixuweiok@sina.com")
# driver.find_element_by_name("password").send_keys("lixuwei44")
#
# driver.find_element_by_xpath("//*[@id=\"pl_login_form\"]/div/div[3]/div[6]/a").click()
#
driver.save_screenshot('screen1.png')

driver.close()